<?php
class CandidatesFForm extends BaseFormAdmin{
	public function configure(){
		$working = AdminArrayData::getWorkingStatus();
		$workKind = AdminArrayData::getWorkKind();
		$gender = AdminArrayData::getGender();
		$married = AdminArrayData::getMarried();
		$training = AdminArrayData::getJapanTraining();
		$working_experience_foreigns = array(
			'0'			=> __('experience_0', null, 'candidate_candidates'),
			'1'			=> '1',
			'2'			=> '2',
			'3'			=> '3',
			'4'			=> '4',
			'5'			=> '5',				
			'6'			=> '6',
			'7'			=> '7',
			'8'			=> '8',
			'9'			=> '9',
			'10'			=> '10'
			
		);
		
		$this->setWidgets(array(
				'resource_id'		=> new sfWidgetFormDoctrineChoice(array(
						'model' 			=> 'CandidateResources', 
						'query'				=> Doctrine_Query::create()
												->select('b.id, b.name')
												->from('CandidateResources b')
												->where('b.is_enabled = 1 AND b.is_deleted = 0 AND (b.updated_at IS NULL OR b.updated_at >= b.created_at)')
												->orderBy('b.name asc'),
						'multiple'	=> false, 
						'add_empty' => __('option_select', null, 'table_list'))),
				'salary_id'	=> new sfWidgetFormDoctrineChoice(array(
						'model' 	=> 'MasterSalaries',
								
						'query'		 => Doctrine_Query::create()
										->select('b.id, concat(b.salary_from, " - ", b.salary_to) as name')
										->from('MasterSalaries b')
										->where('b.is_enabled = 1 AND b.is_deleted = 0 AND (b.updated_at IS NULL OR b.updated_at >= b.created_at)'),
						'multiple' 	=> false,
						'add_empty' => __('option_select', null, 'table_list'))),
				'full_name'			=> new sfWidgetFormInputText(),
				'email'				=> new sfWidgetFormInputText(),
				'address'			=> new sfWidgetFormInputText(),
				'date_of_birth' 	=> new sfWidgetFormInputText(),
				'gender' 			=> new sfWidgetFormChoice(array('choices'=>$gender,'expanded'=>false)),
				'phone_number' 				=> new sfWidgetFormInputText(),
				
				'location_city_id'			=> new sfWidgetFormDoctrineChoice(array('model' => 'LocationCities', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('LocationCities b')->orderBy('b.sort_order desc, b.name asc'),'multiple' => false, 'add_empty' => __('option_select', null, 'table_list'))),
				'location_district_id' 		=> new sfWidgetFormInputText(),
				'home_city_id'			=> new sfWidgetFormDoctrineChoice(array('model' => 'LocationCities', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('LocationCities b')->orderBy(' b.sort_order desc, b.name asc'),'multiple' => false, 'add_empty' => __('option_select', null, 'table_list'))),
				'home_district_id' 		=> new sfWidgetFormInputText(),
				'working_status' 			=> new sfWidgetFormChoice(array('choices'=>$working,'expanded'=>false)),
				'work_kind' 				=> new sfWidgetFormChoice(array('choices'=>$workKind,'expanded'=>false)),
				'salary_require' 			=> new sfWidgetFormInputText(),
				'remark' 					=> new sfWidgetFormTextarea(),
				'register_date' 					=> new sfWidgetFormInputText(),
				
				'more_skill' 					=> new sfWidgetFormInputText(),
				'more_skill_description' 		=> new sfWidgetFormTextarea(),
				
				'telephone' 				=> new sfWidgetFormInputText(),
				'otherphone' 				=> new sfWidgetFormInputText(),
				'contact_address'			=> new sfWidgetFormInputText(),
				'home_address'			=> new sfWidgetFormInputText(),
				'is_married' 			=> new sfWidgetFormChoice(array('choices'=>$married,'expanded'=>false)),
				'is_japan_training' 			=> new sfWidgetFormChoice(array('choices'=>$training,'expanded'=>false)),
				#'job_hope'				=> new sfWidgetFormInputText(),
				'working_experience_foreign'				=> new sfWidgetFormChoice(array('choices'=>$working_experience_foreigns,'expanded'=>false)),
				
				'identity_card' 			=> new sfWidgetFormInputText(),
				'education' 				=> new sfWidgetFormInputText(),
				'total_experience_year' 	=> new sfWidgetFormInputText(),
		));

		$this->setValidators(array(
				'resource_id'			=> new sfValidatorDoctrineChoice(array('model' => 'CandidateResources', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('CandidateResources b')->where('b.is_enabled = 1 AND b.is_deleted = 0 AND (b.updated_at IS NULL OR b.updated_at >= b.created_at)'), 'required' => true),array('required'=> 'input resource_id')),
				'salary_id'				=> new sfValidatorDoctrineChoice(array('model' => 'MasterSalaries', 'query' => Doctrine_Query::create()->select('b.id')->from('MasterSalaries b')->where('b.is_enabled = 1 AND b.is_deleted = 0 AND (b.updated_at IS NULL OR b.updated_at >= b.created_at)'), 'required' => true),array('required'=> 'input salary_id')),
				'full_name'				=> new sfValidatorString(array('max_length' => 255, 'required' => false)),
				'email' 				=> new sfValidatorString(array('required' => false)),
				'address' 				=> new sfValidatorString(array('required' => false)),
				'date_of_birth'				=> new sfValidatorString(array('required'=>false)),
				'gender'					=> new sfValidatorChoice(array('choices'=>array_keys($gender))),
				
				'phone_number'		 		=> new sfValidatorString(array('required'=>false)),
				'location_city_id'		=> new sfValidatorString(array('required' => false)),
				'location_district_id'	=> new sfValidatorString(array('required' => false)),
				'home_city_id'		=> new sfValidatorString(array('required' => false)),
				'home_district_id'	=> new sfValidatorString(array('required' => false)),
				'working_status'		=> new sfValidatorChoice(array('choices'=>array_keys($working))),
				'work_kind'				=> new sfValidatorChoice(array('choices'=>array_keys($workKind))),
				'salary_require'		=> new sfValidatorString(array('required' => false)),
				'remark'				=> new sfValidatorString(array('required' => false)),
				'register_date'				=> new sfValidatorString(array('required' => false)),
				
				'more_skill'				=> new sfValidatorString(array('required' => false)),
				'more_skill_description'	=> new sfValidatorString(array('required' => false)),
				
				
				'telephone' 				=> new sfValidatorString(array('required' => false)),
				'otherphone' 				=> new sfValidatorString(array('required' => false)),
				'contact_address'			=> new sfValidatorString(array('required' => false)),
				'home_address'			=> new sfValidatorString(array('required' => false)),
				'is_married' 			=> new sfValidatorChoice(array('choices'=>array_keys($married))),
				'is_japan_training' 			=> new sfValidatorChoice(array('choices'=>array_keys($training))),
				#'job_hope'			=> new sfValidatorString(array('required' => false)),
				'working_experience_foreign' 			=> new sfValidatorChoice(array('choices'=>array_keys($working_experience_foreigns))),
				
				'identity_card'			=> new sfValidatorString(array('required' => false)),
				'education'				=> new sfValidatorString(array('required' => false)),
				'total_experience_year'				=> new sfValidatorString(array('required' => false))
				
		));
		parent::configure();
		$this->setDefault('working_status', '0');
		$this->setDefault('work_kind', '1');
		$this->setDefault('gender', '0');
		$this->setDefault('salary_require', '0');
		$this->setDefault('total_experience_year', '0');
		$this->setDefault('is_married', '0');
		$this->setDefault('is_japan_training', '0');
		$this->setDefault('register_date', date('d-m-Y', time()));
		/*
		 * Setting name of form
		*/
		$this->widgetSchema->setNameFormat('Candidates[%s]');
		$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
	}
}
